package com.yangzb.sample.hadoop.mapreduce;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.mapreduce.ImportTsv;
import org.apache.hadoop.security.UserGroupInformation;
import org.apache.hadoop.util.GenericOptionsParser;

import java.io.IOException;

/**
 * @author yzb
 */
public class ImportTsvTest {
    public static Configuration conf;
    static {
//        System.out.println(System.getProperty("java.class.path"));
//        System.setProperty("HADOOP_USER_NAME", "tydic_hbjfzx_bqgl");
//        System.setProperty("java.security.krb5.conf", "/etc/krb5.conf");
//        System.setProperty("sun.security.krb5.debug", "true");


        conf = HBaseConfiguration.create();
//        conf = new Configuration();
//        conf.set("hbase.zookeeper.quorum", "zookenode1,zookenode2,zookenode3");
//        conf.set("hbase.zookeeper.property.clientPort", "2181");
//        conf.set("hadoop.security.authentication", "Kerberos");
//        conf.set("keytab.file", "Kerberos");
//        conf.set("hbase.security.authentication", "kerberos");
        conf.set("zookeeper.znode.parent", "/hbase-secure");
//        HadoopUtil.kerberosAuthentication("/data06/tydic_hbjfzx_bqgl/tydic_hbjfzx_bqgl.keytab","tydic_hbjfzx_bqgl@EXAMPLE.COM","EXAMPLE.COM","hbibdc01","/etc/krb5.conf");

//        conf.set("hbase.master.kerberos.principal", "tydic_hbjfzx_bqgl@EXAMPLE.COM");
//        UserGroupInformation.setConfiguration(conf);
//        try {
//            UserGroupInformation ugi = UserGroupInformation.loginUserFromKeytabAndReturnUGI("tydic_hbjfzx_bqgl@EXAMPLE.COM", "/data06/tydic_hbjfzx_bqgl/tydic_hbjfzx_bqgl.keytab");
//            UserGroupInformation.setLoginUser(ugi);
//
//        } catch (Exception e) {
//            e.printStackTrace();
//        }

    }

    public static void main(String[] args) throws Exception {
        String conf = "-Dmapred.job.queue.name=root.tydic_hbjfzx_bqgl -Dimporttsv.separator=, -Dimporttsv.bulk.output=/user/tydic_hbjfzx_bqgl/yzb/"+System.currentTimeMillis()+" -Dimporttsv.columns=HBASE_ROW_KEY,info:c01 tydic_hbjfzx_bqgl:yzb_test hdfs://hbdxcluster/user/tydic_hbjfzx_bqgl/yzb/1.txt";
//        org.apache.hadoop.hbase.mapreduce.ImportTsv.createSubmittableJob(new Configuration(),conf.split(" "));
        String[] s = conf.split(" ");
//        ImportTsv.main(s);
        GenericOptionsParser parser = new GenericOptionsParser(ImportTsvTest.conf, s);
        String[] toolArgs = parser.getRemainingArgs();
        ImportTsv importTsv = new ImportTsv();
        importTsv.setConf(ImportTsvTest.conf);
        importTsv.run(toolArgs);

//        try {
//            Connection connection = ConnectionFactory.createConnection(ImportTsvTest.conf);
//            TableName[] tableNames = connection.getAdmin().listTableNames();
//            for (TableName tableName : tableNames) {
//                System.out.println(tableName.getNameAsString());
//            }
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
    }
}
